#include "STC89C51RC_RD_PLUS.h"
#include "DEFINE.h"

extern void isp_program_byte(uint add, uchar dat);
extern void isp_erase_sector(uchar  num);
extern uchar isp_read_byte(uint add);
void delay2(uint x);

uchar idata read_buf[58];  	

uchar  idata data_buf[58] = {
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
	0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
	0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23,
	0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39
};

void read(void);
void write(void);

void main()
{
	uchar m;
	AUXR |= 0x01;		//disable ale
	isp_erase_sector(0);
	write();
	read();

/*check EEPROM successful*/	
while(1)
{
	for (m = 0; m < 58; m++)
 	{
        if(read_buf[m] !=data_buf[m])	//check fail
		{
		delay2(2000);	
		P1 = 0xAA;			
		P3 = m;							//show fail address
		P2 = read_buf[m];				//show read data
		P0 = data_buf[m];				//show correct data
		}
		
		else{							//check pass
		delay2(100);
		P1 = 0x55;}

	}
}
}

void read(void)
{
	uchar m;
	for (m = 0; m < 58; m++) {

        read_buf[m] =isp_read_byte(m); 
	}

}

void write(void)
{
	uchar m;

	for (m = 0; m < 58; m++) {

		isp_program_byte(m, data_buf[m]);

	}

}

void delay2(uint x)   //1ms
{
	uchar y;
	while (x--) {
		y = 110;
		while (y--) {
			;}
	}
}
